package cn.itcast.mq.Listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MsgListener {

    //@RabbitListener(queues = "queue_test01")
    @RabbitListener(queues = "fanout.queue1")
    public void getMessage1(String msg){
        System.out.println("接收到消息1"+ msg);
    }

    @RabbitListener(queues = "fanout.queue2")
    public void getMessage2(String msg){
        System.out.println("接收到消息2"+ msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue1"),
            exchange = @Exchange(name = "itcast.direct",
            type = ExchangeTypes.DIRECT),
            key = {"red","yellow"}
    ))
    public void getMessage3(String msg){
        System.out.println("接收到消息3"+ msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue2"),
            exchange = @Exchange(name = "itcast.direct",
                    type = ExchangeTypes.DIRECT),
            key = {"red","blue"}
    ))
    public void getMessage4(String msg){
        System.out.println("接收到消息4"+ msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue1"),
            exchange = @Exchange(name = "itcast.topic",
                    type = ExchangeTypes.TOPIC),
            key = {"china.#"}
    ))
    public void getMessage5(String msg){
        System.out.println("接收到消息5"+ msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue2"),
            exchange = @Exchange(name = "itcast.topic",
                    type = ExchangeTypes.TOPIC),
            key = {"#.news"}
    ))
    public void getMessage6(String msg){
        System.out.println("接收到消息6"+ msg);
    }
}